<%@page import="com.model.BoardBean"%>
<%@page import="com.model.PagingBean"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<style type="text/css">
		* {
			-moz-outline-style: none;
		}
		
		:focus {
			-moz-outline-style: none;
		}
		
		#navi {
			float: left;
			width: 250px;
			position: absolute;
		}
		
		#content {
			position: relative;
		}
		
		th {
			background-color: silver;
		}
		
		#boardBtn {
			border-style: solid;
			border-color: white;
		}
	</style>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
	<script type="text/javascript">
		jQuery(document).ready(function() {
	        
	        $("tr.rows").live("mouseover", function(){
				$(this).css("background", "pink");
				$(this).find(".id").css("background", "white");
			});
			
			$("tr.rows").live("mouseout", function(){
				$(this).css("background", "white");			
				$(this).find(".id").css("background", "white");
			});
	            
			$(".rows").live("click", function() {
				// alert("click call "+$("td", this).eq(0).text() + "::" +
				// $("td", this).eq(3).text());
				var no = $("td", this).eq(0).text();
				location = "detailBoard.do?no=" + no;
	
			});
	
			$("#addForm").live("click", function() {
				$(".divAddForm").css("visibility", "visible");
			});
	
			$("#search").click(
					function() {
						if ($("#searchSentence").val() == "") {
							alert("검색할 문장을 입력해 주세요.")
						} else {
							// var sql = " where " + $("#selectKind").val() + "
							// like %" + $("#searchSentence").val() + "%";
							// alert(sql);
							location = "search.do?kind=" + $("#selectKind").val() + "&sentence=" + $("#searchSentence").val();
						}
					});
	
			$("#selectKind").click(function() {
				$("#searchSentence").val("");
			});
	
			function deleteMember() {
				location = "deleteMember.do?id=" + $("#in_id").val();
			}
			
			$("#login").click(function(){
				if( $("#login_input").val() == ""){
					alert("아이디와 비밀번호를 입력해 주세요.");

				}else{
					$("#loginForm").submit();
				}

			});
			
			if( ${ cookie.boardUpdateResult.value == "success"} ){
				alert("수정 성공");
			}
			if( ${ cookie.boardUpdateResult.value == "fail"} ){
				alert("수정 실패");
			}
		});
	</script>
</head>
<body>
	<div id="top">
		<h2 align="center">게시판</h2>
		<hr>
	</div>
	<div id="navi">
		<!-- 문제점 발견 firefox에서는 입력이 안됨 -->
		<fieldset>
			<legend>로그인</legend>
			<c:if test="${ empty sessionScope.sessionLoginID }">
				<form action="loginIdPwdCheck.do" method="post" id="loginForm" class="loginForm">
					<table>
						<tr>
							<td>아이디</td>
							<td>
								<input type="text" id="login_input" name="m_id" size="20" />
							</td>
						</tr>
						<tr>
							<td>비밀번호</td>
							<td>
								<input type="password" id="login_input" name="m_pw"  size="21" />
							</td>
						</tr>
						<tr>
							<td colspan="2" align="center">
								<p>
								<input type="button" id="login" value="로그인" />
								<input type="button" value="회원가입" onclick="location.href='memberForm.do';" />
							</td>
						</tr>
					</table>
				</form>
			</c:if>
			<c:if test="${ ! empty sessionScope.sessionLoginID }">
				<jsp:include page="../login/loging.jsp" flush="true"/>
			</c:if>
		</fieldset>
	</div>
	<div id="content">
		<table align="center" width="800">
			<tr>
				<c:if test="${ paging != null }">
					<td align="right"><b>총 게시물 수 : ${ paging.totalCount }</b></td>
				</c:if>
				<c:if test="${ searchPaging != null }">
					<td align="right"><b>검색된 게시물 수 : ${ searchPaging.totalCount }</b></td>
				</c:if>
			</tr>
		</table>
		<table border="1" align="center" width="800px">
			<tr>
				<th>번호</th>
				<th>제목</th>
				<th>작성자</th>
				<th>게시일</th>
				<th>조회수</th>
			</tr>
			<c:forEach var="list" items="${ listBoard }">
				<tr class="rows">
					<td align="center">${ list.b_no }</td>
					<td width="500px">
						<font color="blue">
							&nbsp;
							${ list.b_title }
						</font>
					</td>
					<td align="center">${ list.b_writer }</td>
					<td align="center">${ list.b_regdate }</td>
					<td align="center">${ list.b_hit }</td>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="5" align="center">
					<c:if test="${ paging != null }">
						<jsp:include page="paging.jsp">
							<jsp:param name="actionPath" value="listBoard.do"/>
							<jsp:param name="totalCount" value="${ paging.totalCount }"/>
							<jsp:param name="countPerPage" value="${ paging.countPerPage }"/>
							<jsp:param name="blockCount" value="${ paging.blockCount }"/>
							<jsp:param name="nowPage" value="${ paging.nowPage }"/>
						</jsp:include>
					</c:if>
					<c:if test="${ searchPaging != null }">
						<jsp:include page="paging.jsp">
							<jsp:param name="actionPath" value="listBoard.do"/>
							<jsp:param name="totalCount" value="${ searchPaging.totalCount }"/>
							<jsp:param name="countPerPage" value="${ searchPaging.countPerPage }"/>
							<jsp:param name="blockCount" value="${ searchPaging.blockCount }"/>
							<jsp:param name="nowPage" value="${ searchPaging.nowPage }"/>
						</jsp:include>
					</c:if>
				</td>
			</tr>
			<tr>
				<td colspan="5" align="right" id="boardBtn">
					<c:if test="${ empty sessionScope.sessionLoginID }">
						<input disabled="disabled" type="button" value="글쓰기" onclick="location.href='boardForm.do';">
					</c:if>
					<c:if test="${ ! empty sessionScope.sessionLoginID }">
						<input type="button" value="글쓰기" onclick="location.href='boardForm.do';">
					</c:if>
					
					<!-- <input type="button" value="추가" id="addForm"> -->
					<br>
				</td>
			</tr>
		</table>
		<br>
		<center>
			<select id="selectKind">
				<option value="b_title">제목</option>
				<option value="b_writer">작성자</option>
				<option value="b_no">게시물번호</option>
			</select>
			&nbsp;
			<input type="text" id="searchSentence" size="50" />
			&nbsp;
			<input type="button" value="검색" id="search">
			&nbsp;
			<input type="button" value="전체목록" onclick="location.href='listBoard.do'">
		</center>
		
	</div>
	<%-- <div class="divAddForm" style="visibility: hidden;">
		<jsp:include page="./boardForm.jsp"></jsp:include>
	</div> --%>
</body>
</html>